package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ListView;

import com.example.myapplication.adapter.CartAdapter;
import com.example.myapplication.bean.Product;

import java.util.ArrayList;
import java.util.List;

public class CartActivity extends AppCompatActivity {

    String[] names = new String[]{"中国十大名茶", "全自动雨伞", "蓝色军刀"};
    int[] types = new int[] {0, 1, 1};
    int[] prices = new int[] {149, 328, 469};
    int[] countes = new int[] {2, 1, 1};
    int[] images = new int[] {R.drawable.tea, R.drawable.umbrella, R.drawable.bag};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cart);

        List<Product> data = new ArrayList<>();
        for(int i=0; i<3; i++) {
            data.add(new Product(images[i], names[i], types[i], prices[i], countes[i]));
        }

        CartAdapter cartAdapter =
                new CartAdapter(this, R.layout.cart_listview_item, data);
        // 关联ListView
        ListView listView = findViewById(R.id.list_view);
        listView.setAdapter(cartAdapter);       // 设置adapter

    }
}